* (bug 472) Syndication feeds for the last few edits of page history
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 28 May 2006 03:47:28 +0000 (03:47 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 28 May 2006 03:47:28 +0000 (03:47 +0000)
* Format edit comments in Recent Changes feed
* Switch incorrectly ordered column headers on Recent Changes feed diffs

RELEASE-NOTES
includes/PageHistory.php
includes/SpecialRecentchanges.php
languages/Messages.php

index 609f25f..9f6f61b 100644 (file)
@@ -367,6 +367,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   allow the including parser to do it.
 * Fix {{int:}} to use content language, so it won't break caches and links
   tables and randomly include data from the wrong language.
+* (bug 472) Syndication feeds for the last few edits of page history
+* Format edit comments in Recent Changes feed
+* Switch incorrectly ordered column headers on Recent Changes feed diffs
 
 
 == Compatibility ==
index 4cfee47..3e413c8 100644 (file)
@@ -71,6 +71,13 @@ class PageHistory {
                $wgOut->setArticleFlag( false );
                $wgOut->setArticleRelated( true );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setSyndicated( true );
+
+               $feedType = $wgRequest->getVal( 'feed' );
+               if( $feedType ) {
+                       wfProfileOut( $fname );
+                       return $this->feed( $feedType );
+               }
 
                /*
                 * Fail if article doesn't exist.
@@ -562,6 +569,91 @@ class PageHistory {
                                $this->mTitle, $text,
                                wfArrayToCGI( $query, array( 'action' => 'history' )));
        }
+       
+       
+       /**
+        * Output a subscription feed listing recent edits to this page.
+        * @param string $type
+        */
+       function feed( $type ) {
+               require_once 'Feed.php';
+               require_once 'SpecialRecentchanges.php';
+               
+               global $wgFeedClasses;
+               if( !isset( $wgFeedClasses[$type] ) ) {
+                       global $wgOut;
+                       $wgOut->addWikiText( wfMsg( 'feed-invalid' ) );
+                       return;
+               }
+               
+               $feed = new $wgFeedClasses[$type](
+                       $this->mTitle->getPrefixedText() . ' - ' . wfMsg( 'revhistory' ),
+                       'Revision history for this page on the wiki',
+                       $this->mTitle->getFullUrl( 'action=history' ) );
+
+               $items = $this->fetchRevisions(10, 0, DIR_NEXT);
+               $feed->outHeader();
+               if( $items ) {
+                       foreach( $items as $row ) {
+                               $feed->outItem( $this->feedItem( $row ) );
+                       }
+               } else {
+                       $feed->outItem( $this->feedEmpty() );
+               }
+               $feed->outFooter();
+       }
+       
+       function feedEmpty() {
+               global $wgOut;
+               return new FeedItem(
+                       wfMsgForContent( 'nohistory' ),
+                       $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
+                       $this->mTitle->getFullUrl(),
+                       wfTimestamp( TS_MW ),
+                       '',
+                       $this->mTitle->getTalkPage()->getFullUrl() );
+       }
+       
+       /**
+        * Generate a FeedItem object from a given revision table row
+        * Borrows Recent Changes' feed generation functions for formatting;
+        * includes a diff to the previous revision (if any).
+        *
+        * @param $row
+        * @return FeedItem
+        */
+       function feedItem( $row ) {
+               $rev = new Revision( $row );
+               $text = rcFormatDiffRow( $this->mTitle,
+                       $this->mTitle->getPreviousRevisionID( $rev->getId() ),
+                       $rev->getId(),
+                       $rev->getTimestamp(),
+                       $rev->getComment() );
+               
+               if( $rev->getComment() == '' ) {
+                       global $wgContLang;
+                       $title = wfMsgForContent( 'history-feed-item-nocomment',
+                               $rev->getUserText(),
+                               $wgContLang->timeanddate( $rev->getTimestamp() ) );
+               } else {
+                       $title = $rev->getUserText() . ": " . $this->stripComment( $rev->getComment() );
+               }
+
+               return new FeedItem(
+                       $title,
+                       $text,
+                       $this->mTitle->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
+                       $rev->getTimestamp(),
+                       $rev->getUserText(),
+                       $this->mTitle->getTalkPage()->getFullUrl() );
+       }
+       
+       /**
+        * Quickie hack... strip out wikilinks to more legible form from the comment.
+        */
+       function stripComment( $text ) {
+               return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
+       }
 
 
 }
index 0c05104..74c6ebf 100644 (file)
@@ -614,27 +614,41 @@ function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) {
  * Format a diff for the newsfeed
  */
 function rcFormatDiff( $row ) {
-       global $wgFeedDiffCutoff, $wgContLang;
+       $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
+       return rcFormatDiffRow( $titleObj,
+               $row->rc_last_oldid, $row->rc_this_oldid,
+               $row->rc_timestamp,
+               $row->rc_comment );
+}
+
+function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment ) {
+       global $wgFeedDiffCutoff, $wgContLang, $wgUser;
        $fname = 'rcFormatDiff';
        wfProfileIn( $fname );
 
        require_once( 'DifferenceEngine.php' );
-       $completeText = '<p>' . htmlspecialchars( $row->rc_comment ) . "</p>\n";
+       $skin = $wgUser->getSkin();
+       $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
 
-       if( $row->rc_namespace >= 0 ) {
-               if( $row->rc_last_oldid ) {
+       if( $title->getNamespace() >= 0 ) {
+               if( $oldid ) {
                        wfProfileIn( "$fname-dodiff" );
 
-                       $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
-                       $de = new DifferenceEngine( $titleObj, $row->rc_last_oldid, $row->rc_this_oldid );
-                       $diffText = $de->getDiff( wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
-                               wfMsg( 'currentrev' ) );
+                       $de = new DifferenceEngine( $title, $oldid, $newid );
+                       #$diffText = $de->getDiff( wfMsg( 'revisionasof',
+                       #       $wgContLang->timeanddate( $timestamp ) ),
+                       #       wfMsg( 'currentrev' ) );
+                       $diffText = $de->getDiff(
+                               wfMsg( 'previousrevision' ), // hack
+                               wfMsg( 'revisionasof',
+                                       $wgContLang->timeanddate( $timestamp ) ) );
+                               
 
                        if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
                                // Omit large diffs
-                               $diffLink = $titleObj->escapeFullUrl(
-                                       'diff=' . $row->rc_this_oldid .
-                                       '&oldid=' . $row->rc_last_oldid );
+                               $diffLink = $title->escapeFullUrl(
+                                       'diff=' . $newid .
+                                       '&oldid=' . $oldid );
                                $diffText = '<a href="' .
                                        $diffLink .
                                        '">' .
@@ -642,7 +656,7 @@ function rcFormatDiff( $row ) {
                                        '</a>';
                        } elseif ( $diffText === false ) {
                                // Error in diff engine, probably a missing revision
-                               $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
+                               $diffText = "<p>Can't load revision $newid</p>";
                        } else {
                                // Diff output fine, clean up any illegal UTF-8
                                $diffText = UtfNormal::cleanUp( $diffText );
@@ -650,7 +664,7 @@ function rcFormatDiff( $row ) {
                        }
                        wfProfileOut( "$fname-dodiff" );
                } else {
-                       $rev = Revision::newFromId( $row->rc_this_oldid );
+                       $rev = Revision::newFromId( $newid );
                        if( is_null( $rev ) ) {
                                $newtext = '';
                        } else {
index b9c7b99..6211b51 100644 (file)
@@ -251,6 +251,7 @@ See $1.',
 'viewdeleted' => 'View $1?',
 'restorelink' => '{{PLURAL:$1|one deleted edit|$1 deleted edits}}',
 'feedlinks' => 'Feed:',
+'feed-invalid' => 'Invalid subscription feed type.',
 'sitenotice'   => '-', # the equivalent to wgSiteNotice
 'anonnotice' => '-',
 
@@ -589,6 +590,11 @@ there may be details in the [{{fullurl:Special:Log/delete|page={{PAGENAMEE}}}} d
 #'rev-delundel' => 'del/undel',
 'rev-delundel' => 'show/hide',
 
+'history-feed-item-nocomment' => '$1 at $2', # user at time
+'history-feed-empty' => 'The requested page doesn\'t exist.
+It may have been deleted from the wiki, or renamed.
+Try [[Special:Search|searching on the wiki]] for relevant new pages.',
+
 # Revision deletion
 #
 'revisiondelete' => 'Delete/undelete revisions',